#models.py : 模型，数据库
from .exts import db
class Department(db.Model):
    __tablename__ = 'department'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50),unique=True)
    wages = db.Column(db.DECIMAL(10,2))
    users = db.relationship('User', backref='department', lazy='dynamic')

department_job = db.Table('department_job',
    db.Column('department_id', db.Integer, db.ForeignKey('department.id'), primary_key=True),
    db.Column('job_id', db.Integer, db.ForeignKey('job.id'), primary_key=True),
    db.Column('overtime_pay', db.DECIMAL(10,2))
                        )

class Job(db.Model):
    __tablename__ = 'job'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50),unique=True)
    wages = db.Column(db.DECIMAL(10,2))
    users = db.relationship('User', backref='job', lazy='dynamic')

class User(db.Model):
    __tablename__ = 'user'
    id = db.Column(db.Integer, primary_key=True,autoincrement=True)
    name = db.Column(db.String(50))
    gender = db.Column(db.Boolean,default=False)
    number = db.Column(db.Text)
    department_id = db.Column(db.Integer,db.ForeignKey('department.id'))
    job_id = db.Column(db.Integer,db.ForeignKey('job.id'))
    overtime = db.Column(db.DECIMAL(10,2),default=0)
    username = db.relationship('Username', back_populates='user', uselist=False)

class Username(db.Model):
    __tablename__ = 'username'
    user_id = db.Column(db.Integer,db.ForeignKey('user.id'),primary_key=True)
    username = db.Column(db.String(50),unique=True)
    password = db.Column(db.String(200))
    email = db.Column(db.String(200))
    user = db.relationship('User', back_populates='username', uselist=False)

class Admin(db.Model):
    __tablename__ = 'admin'
    id = db.Column(db.Integer,primary_key=True,autoincrement=True)
    admin = db.Column(db.String(50),unique=True)
    password = db.Column(db.String(200))